package com.qcby.mybatis01.plugin;

import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.executor.parameter.ParameterHandler;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.reflection.DefaultReflectorFactory;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

/**
 * @className: SQlLogPlugin
 * @description:
 * @author: lxt
 * @create: 2021-06-04 15:28
 **/
//args: 你需要mybatis传入什么参数给你 type :你需要拦截的对象  method=要拦截的方法
@Intercepts(
        @Signature(type = Executor.class,method ="query",args = {MappedStatement.class,Object.class, RowBounds.class, ResultHandler.class})
)
public class SQlLogPlugin1 implements Interceptor {

    private String methodPageFlag;

    public Object intercept(Invocation invocation) throws Throwable {
        System.out.println("......................Executor");
        Object o = invocation.proceed();
        System.out.println("......................Executor-after");
        return o;
    }

    public Object plugin(Object target) {
        return Plugin.wrap(target,this);
    }

    public void setProperties(Properties properties) {
        methodPageFlag = properties.getProperty("methodPageFlag");
        System.out.println("testName："+properties.getProperty("testName"));
        System.out.println("methodPageFlag："+methodPageFlag);

    }
}
